home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / WASTE 1.1b1 Distribution / WASTE Source / WEUtilities.p < prev   
Text File  |  1995-06-01  |  3KB  |  121 lines

  1. unit WEUtilities;
  2.  
  3. { WASTE PROJECT }
  4. { Interface to miscellaneous utility routines }
  5. { Most routines are defined in WASTEUtils.Lib }
  6.  
  7. { Copyright © 1993-1995 Marco Piovanelli }
  8. { All Rights Reserved }
  9.  
  10. interface
  11.     uses
  12.         Types, Memory;
  13.  
  14.     const
  15.  
  16. { result codes }
  17.  
  18.         weUndefinedSelectorErr = -50;
  19.  
  20. { values for WEAllocate allocFlags parameter }
  21.  
  22.         kAllocClear = $0001;                        { clear handle after allocation }
  23.         kAllocTemp = $0002;                    { use temporary memory if available }
  24.  
  25.     type
  26.  
  27.         WEFieldDescriptor = record
  28.                 fOffset: Integer;
  29.                 fLength: Integer;
  30.             end;  { WEFieldDescriptor }
  31.  
  32.         WELookupTableElement = record
  33.                 selector: LongInt;
  34.                 desc: WEFieldDescriptor;
  35.             end;  { WELookupTableElement }
  36.         WELookupTableElementPtr = ^WELookupTableElement;
  37.  
  38.         WELookupTable = array[0..0] of WELookupTableElement;
  39.  
  40.     var
  41.  
  42. { externally defined global variables }
  43.  
  44. {$PUSH}
  45. {$J+}
  46.  
  47.         _weMainSelectorTable: WELookupTable;
  48.         _weObjectHandlerSelectorTable: WELookupTable;
  49.  
  50. {$POP}
  51.  
  52.     procedure _WEForgetHandle (var h: univ Handle);
  53.     function _WESetHandleLock (h: univ Handle;
  54.                                     lock: Boolean): Boolean;
  55.     procedure _WEBlockClr (blockPtr: Ptr;
  56.                                     blockSize: Size);
  57.     function _WEBlockCmp (block1, block2: Ptr;
  58.                                     blockSize: Size): Boolean;
  59.     function _WEInsertSlot (h: univ Handle;
  60.                                     element: univ Ptr;
  61.                                     insertAt: LongInt;
  62.                                     slotSize: Size): OSErr;
  63.     function _WERemoveSlot (h: univ Handle;
  64.                                     removeAt: LongInt;
  65.                                     slotSize: Size): OSErr;
  66.     procedure _WEReorder (var a, b: LongInt);
  67.     function _WEGetField ({const}
  68.                                     var table: WELookupTable;
  69.                                     selector: OSType;
  70.                                     info: univ Ptr;
  71.                                     structure: univ Ptr): OSErr;
  72.     function _WESetField ({const}
  73.                                     var table: WELookupTable;
  74.                                     selector: OSType;
  75.                                     info: univ Ptr;
  76.                                     structure: univ Ptr): OSErr;
  77.     function _WEAllocate (blockSize: Size;
  78.                                     allocFlags: Integer;
  79.                                     var h: univ Handle): OSErr;
  80.  
  81. implementation
  82.  
  83.     function _WEAllocate (blockSize: Size;
  84.                                     allocFlags: Integer;
  85.                                     var h: univ Handle): OSErr;
  86.  
  87. { Allocate a new relocatable block. }
  88. { AllocFlags may specify whether the block should be cleared and whether }
  89. { temporary memory should be used. }
  90.  
  91.         var
  92.             theHandle: Handle;
  93.             err: OSErr;
  94.     begin
  95.         theHandle := nil;
  96.  
  97. { if kAllocTemp is specified, try tapping temporary memory }
  98.         if (BAND(allocFlags, kAllocTemp) <> 0) then
  99.             theHandle := TempNewHandle(blockSize, err);
  100.  
  101. { if kAllocTemp isn't specified, or TempNewHandle failed, try with current heap }
  102.         if (theHandle = nil) then
  103.             begin
  104.                 theHandle := NewHandle(blockSize);
  105.                 err := MemError;
  106.             end;
  107.  
  108. { if kAllocClear is specified, zero the block }
  109.         if (BAND(allocFlags, kAllocClear) <> 0) then
  110.             if (theHandle <> nil) then
  111.                 _WEBlockClr(theHandle^, blockSize);
  112.  
  113. { return handle through VAR parameter }
  114.         h := theHandle;
  115.  
  116. { return result code }
  117.         _WEAllocate := err;
  118.  
  119.     end;  { _WEAllocate }
  120.  
  121. end.